﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Globalization;
using System.Windows.Data;
using System.Windows.Media;

namespace SudokuWPF.Converter
{
    /// <summary>
    /// 用于转换状态条的颜色
    /// </summary>
    [ValueConversion(typeof(int), typeof(Color))]
    public class BarColorConverter : IValueConverter
    {
        static Color[] BarColors = {
                                    Colors.SteelBlue,
                                    Colors.Green,
                                    Colors.Firebrick,
                                    Colors.DarkSlateGray,
                                    Colors.Orange,
                                    Colors.Khaki
                                    };
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            int v = (int)value;
            return BarColors[v % BarColors.Length];
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            Color v = (Color)value;
            return Array.IndexOf<Color>(BarColors, v);
        }

    }
}
